using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Web.Security;
using FAQComponents.API;

namespace Adge.Web.Faq
{
	/// <summary>
	/// Summary description for Login.
	/// </summary>
	public partial class Login : System.Web.UI.Page
	{
	
		protected void Page_Load(object sender, System.EventArgs e)
		{
			// Put user code to initialize the page here
		}		

		protected void btnLogin_Click(object sender, System.EventArgs e)
		{
            string userId = username.Text;
            string pwd = password.Text;
            if (UserAPI.IsValidCredentials(userId, pwd))
            {
                FormsAuthentication.SetAuthCookie(userId, rememberMe.Checked);
                HttpContext.Current.Response.Redirect(FormsAuthentication.GetRedirectUrl(userId, rememberMe.Checked), true);
                //FormsAuthentication.RedirectFromLoginPage(username.Text, rememberMe.Checked);
            }
            else
            {
                Page.ClientScript.RegisterStartupScript(typeof(Login), "invalidLogin", "<script language=\"JavaScript\">alert('Your username and/or password are invalid.  Please try again.');</script>");
            }
            return;

            //{
            //    string sPassword = FormsAuthentication.HashPasswordForStoringInConfigFile(pwd, "md5");
            //    object userID = yaf.DB.user_login(1, userId, sPassword);
                
            //    if ((!object.ReferenceEquals(userID, DBNull.Value)))
            //    {
            //        string idName = string.Format("{0};{1};{2}", userID, 1, userId);
            //        FormsAuthentication.SetAuthCookie(userId, rememberMe.Checked);
            //        HttpContext.Current.Response.Redirect(FormsAuthentication.GetRedirectUrl(userId, rememberMe.Checked), true);
                    
            //    }
            //    else
            //    {
            //        Page.ClientScript.RegisterStartupScript(typeof(Login), "invalidLogin", "<script language=\"JavaScript\">alert('Your username and/or password are invalid.  Please try again.');</script>");
            //        //AddLoadMessage(GetText("password_error")) 
            //    }
            //} 
		}
	}
}
